def pretreatment_done(list):
    sign = -1

    tmp     = {}
    need    = []

    for sample in list:
        if sign == -1 :
            tmp['max']={
                'no':sample['no'],
                'red':sample['red'],
            }
            sign = 0
            continue
        elif sign == 0:
            if tmp['max']['red'] < sample['red']:
                #找到新的最大值
                tmp['max']={
                    'no':sample['no'],
                    'red':sample['red'],
                }

            else:
                #找到了第一个最大值
                tmp['min']={
                    'no':sample['no'],
                    'red':sample['red'],
                }
                sign= 1
                continue
        elif sign == 1:
            if tmp['min']['red'] > sample['red']:
                tmp['min']={
                    'no':sample['no'],
                    'red':sample['red'],
                }
            else:
                #找到了一个最小  进行幅度判断
                #这里认为 波峰->波谷  是半个周期   这里用4判断 可以保证 脉搏225次/min以内的数据不丢失。但不保证准确，待测
                if abs(tmp['min']['no']-tmp['max']['no']) >=4:
                    #通过 将最大写入need
                    need.append(sample['no'])

                    #新的值作为最大的起点
                    tmp['max']={
                        'no':sample['no'],
                        'red':sample['red'],
                    }

                    sign = 0

                else:
                    sign = 2


                tmp.pop('min')
                continue

        elif sign == 2:
            #消除噪音
            if tmp['max']['red'] < sample['red']:
                sign = 0

                tmp['max']={
                    'no':sample['no'],
                    'red':sample['red'],
                }
            else:
                continue


    return need[3:-3]
